//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

#ifndef TERRAIN_H
#define TERRAIN_H


#include "Config.h"
#include "Models/ModelAl.h"
#include <map>

using namespace std;

#define TERRAIN_EMPTY   0x00
#define TERRAIN_WALL    0x01
#define TERRAIN_ENEMY   0x02
#define TERRAIN_PICK_UP 0x04
#define toIdx(x, z) (((int)z + m_nDepth / 2) * m_nWidth + ((int)x + m_nWidth / 2))

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
class CTerrain {

//-----------------------------------------------------------------------------
protected:

  /// terrain width (X)
  int m_nWidth;

  /// terrain depth (Z)
  int m_nDepth;

  /// terrain data
  float *m_pfTerrain;

  /// terrain normals
  float *m_pfNormals;

  /// walls
  unsigned char *m_pszWalls;

  /// texture
  GLuint m_nTexture;

  /// wall texture
  GLuint m_nWallTexture;

  /// vector of enenmies
  map<int, CModelAl *> m_mnpoEnemies;


//-----------------------------------------------------------------------------
public:

  /// constructor
  CTerrain();

  /// destructor
  ~CTerrain();

  /// initialize the terrain
  bool Init(const char *pszFilename, const char *pszTexture, const char *pszWalls,
    const char *pszWallTexture, float fScale = 25.0f);

  /// return the height of a given spatial position
  float GetTerrainHeight(float fX, float fZ);

  /// draw terrain
  void Draw();

  /// validate position
  bool ValidatePosition(float fX, float fZ);

  /// check collision
  float CheckCollisionRay(float *pfPosition, float *pfDirection);

  /// return the terrain width
  int GetWidth() { return m_nWidth; }
};


#endif //TERRAIN_H
